﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Data.SqlClient;
using Entidades.Karaoke;

namespace Datos.Karaoke
{
    public class KarTipoMotivoDAL
    {
        public static string cnx = ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString();


        public static List<KarTipoMotivo> ListarMotivo(int tipo)
        {

            SqlConnection con = new SqlConnection(cnx);
            SqlCommand com = new SqlCommand("[dbo].[SP_KAR_MOTIVOS_LISTAR]", con);
            com.Parameters.AddWithValue("@tipo", tipo);

            com.CommandType = System.Data.CommandType.StoredProcedure;
            try
            {
                con.Open();
                SqlDataReader dr = com.ExecuteReader();
                List<KarTipoMotivo> lista = new List<KarTipoMotivo>();
                KarTipoMotivo obj = null;
                while (dr.Read())
                {
                    obj = new KarTipoMotivo();
                    obj.IdMotivo = Convert.ToInt32(dr["ID"].ToString());
                    obj.Motivo = dr["NOMBRE"].ToString();

                    lista.Add(obj);
                }
                dr.Close();

                return lista;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();

            }

        }
    }
}
